/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.skali.portlet.governmentSpending.service.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.impl.BaseModelImpl;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.Date;
import java.util.Locale;
import java.util.Map;

/**
 * @author Rizwan
 */
public class SpendingTypeClp extends BaseModelImpl<SpendingType>
	implements SpendingType {
	public SpendingTypeClp() {
	}

	public long getPrimaryKey() {
		return _SpendingId;
	}

	public void setPrimaryKey(long pk) {
		setSpendingId(pk);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_SpendingId);
	}

	public long getSpendingId() {
		return _SpendingId;
	}

	public void setSpendingId(long SpendingId) {
		_SpendingId = SpendingId;
	}

	public String getSpendingName() {
		return _SpendingName;
	}

	public String getSpendingName(Locale locale) {
		String languageId = LocaleUtil.toLanguageId(locale);

		return getSpendingName(languageId);
	}

	public String getSpendingName(Locale locale, boolean useDefault) {
		String languageId = LocaleUtil.toLanguageId(locale);

		return getSpendingName(languageId, useDefault);
	}

	public String getSpendingName(String languageId) {
		String value = LocalizationUtil.getLocalization(getSpendingName(),
				languageId);

		if (isEscapedModel()) {
			return HtmlUtil.escape(value);
		}
		else {
			return value;
		}
	}

	public String getSpendingName(String languageId, boolean useDefault) {
		String value = LocalizationUtil.getLocalization(getSpendingName(),
				languageId, useDefault);

		if (isEscapedModel()) {
			return HtmlUtil.escape(value);
		}
		else {
			return value;
		}
	}

	public Map<Locale, String> getSpendingNameMap() {
		return LocalizationUtil.getLocalizationMap(getSpendingName());
	}

	public void setSpendingName(String SpendingName) {
		_SpendingName = SpendingName;
	}

	public void setSpendingName(Locale locale, String SpendingName) {
		String languageId = LocaleUtil.toLanguageId(locale);

		if (Validator.isNotNull(SpendingName)) {
			setSpendingName(LocalizationUtil.updateLocalization(
					getSpendingName(), "SpendingName", SpendingName, languageId));
		}
		else {
			setSpendingName(LocalizationUtil.removeLocalization(
					getSpendingName(), "SpendingName", languageId));
		}
	}

	public void setSpendingNameMap(Map<Locale, String> SpendingNameMap) {
		if (SpendingNameMap == null) {
			return;
		}

		ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			if (contextClassLoader != portalClassLoader) {
				currentThread.setContextClassLoader(portalClassLoader);
			}

			Locale[] locales = LanguageUtil.getAvailableLocales();

			for (Locale locale : locales) {
				String SpendingName = SpendingNameMap.get(locale);

				setSpendingName(locale, SpendingName);
			}
		}
		finally {
			if (contextClassLoader != portalClassLoader) {
				currentThread.setContextClassLoader(contextClassLoader);
			}
		}
	}

	public String getDescription() {
		return _Description;
	}

	public String getDescription(Locale locale) {
		String languageId = LocaleUtil.toLanguageId(locale);

		return getDescription(languageId);
	}

	public String getDescription(Locale locale, boolean useDefault) {
		String languageId = LocaleUtil.toLanguageId(locale);

		return getDescription(languageId, useDefault);
	}

	public String getDescription(String languageId) {
		String value = LocalizationUtil.getLocalization(getDescription(),
				languageId);

		if (isEscapedModel()) {
			return HtmlUtil.escape(value);
		}
		else {
			return value;
		}
	}

	public String getDescription(String languageId, boolean useDefault) {
		String value = LocalizationUtil.getLocalization(getDescription(),
				languageId, useDefault);

		if (isEscapedModel()) {
			return HtmlUtil.escape(value);
		}
		else {
			return value;
		}
	}

	public Map<Locale, String> getDescriptionMap() {
		return LocalizationUtil.getLocalizationMap(getDescription());
	}

	public void setDescription(String Description) {
		_Description = Description;
	}

	public void setDescription(Locale locale, String Description) {
		String languageId = LocaleUtil.toLanguageId(locale);

		if (Validator.isNotNull(Description)) {
			setDescription(LocalizationUtil.updateLocalization(
					getDescription(), "Description", Description, languageId));
		}
		else {
			setDescription(LocalizationUtil.removeLocalization(
					getDescription(), "Description", languageId));
		}
	}

	public void setDescriptionMap(Map<Locale, String> DescriptionMap) {
		if (DescriptionMap == null) {
			return;
		}

		ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			if (contextClassLoader != portalClassLoader) {
				currentThread.setContextClassLoader(portalClassLoader);
			}

			Locale[] locales = LanguageUtil.getAvailableLocales();

			for (Locale locale : locales) {
				String Description = DescriptionMap.get(locale);

				setDescription(locale, Description);
			}
		}
		finally {
			if (contextClassLoader != portalClassLoader) {
				currentThread.setContextClassLoader(contextClassLoader);
			}
		}
	}

	public Date getModifiedDate() {
		return _ModifiedDate;
	}

	public void setModifiedDate(Date ModifiedDate) {
		_ModifiedDate = ModifiedDate;
	}

	public SpendingType toEscapedModel() {
		if (isEscapedModel()) {
			return this;
		}
		else {
			return (SpendingType)Proxy.newProxyInstance(SpendingType.class.getClassLoader(),
				new Class[] { SpendingType.class },
				new AutoEscapeBeanHandler(this));
		}
	}

	public Object clone() {
		SpendingTypeClp clone = new SpendingTypeClp();

		clone.setSpendingId(getSpendingId());
		clone.setSpendingName(getSpendingName());
		clone.setDescription(getDescription());
		clone.setModifiedDate(getModifiedDate());

		return clone;
	}

	public int compareTo(SpendingType spendingType) {
		long pk = spendingType.getPrimaryKey();

		if (getPrimaryKey() < pk) {
			return -1;
		}
		else if (getPrimaryKey() > pk) {
			return 1;
		}
		else {
			return 0;
		}
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		SpendingTypeClp spendingType = null;

		try {
			spendingType = (SpendingTypeClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long pk = spendingType.getPrimaryKey();

		if (getPrimaryKey() == pk) {
			return true;
		}
		else {
			return false;
		}
	}

	public int hashCode() {
		return (int)getPrimaryKey();
	}

	public String toString() {
		StringBundler sb = new StringBundler(9);

		sb.append("{SpendingId=");
		sb.append(getSpendingId());
		sb.append(", SpendingName=");
		sb.append(getSpendingName());
		sb.append(", Description=");
		sb.append(getDescription());
		sb.append(", ModifiedDate=");
		sb.append(getModifiedDate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(16);

		sb.append("<model><model-name>");
		sb.append(
			"com.skali.portlet.governmentSpending.service.model.SpendingType");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>SpendingId</column-name><column-value><![CDATA[");
		sb.append(getSpendingId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>SpendingName</column-name><column-value><![CDATA[");
		sb.append(getSpendingName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>Description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>ModifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _SpendingId;
	private String _SpendingName;
	private String _Description;
	private Date _ModifiedDate;
}